package com.micro.school.edu.controller;

import java.util.List;

import com.micro.school.common.core.context.SecurityContextHolder;
import com.micro.school.common.core.utils.poi.ExcelUtil;
import com.micro.school.common.core.web.controller.BaseController;
import com.micro.school.common.core.web.domain.AjaxResult;
import com.micro.school.common.core.web.page.TableDataInfo;
import com.micro.school.common.log.annotation.Log;
import com.micro.school.common.log.enums.BusinessType;
import com.micro.school.common.security.annotation.RequiresPermissions;
import com.micro.school.common.security.utils.SecurityUtils;
import com.micro.school.edu.domain.vo.CollegeMajorVo;
import com.micro.school.edu.domain.vo.SchoolCampusVo;
import com.micro.school.edu.service.ICollegeMajorService;
import com.micro.school.system.api.domain.vo.CollegeMajorVos;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * 学院专业Controller
 *
 * @author rakic
 * @date 2025-08-07
 */
@RestController
@RequestMapping("/major")
public class CollegeMajorController extends BaseController
{
    @Autowired
    private ICollegeMajorService collegeMajorService;

    /**
     * 查询学院专业列表
     */
    @GetMapping("/list")
    public TableDataInfo list(CollegeMajorVo collegeMajorVo)
    {
        startPage();
        List<CollegeMajorVo> list = collegeMajorService.selectCollegeMajorList(collegeMajorVo);
        return getDataTable(list);
    }

    /**
     * 查询列表不分页
     */
    @PostMapping("/getCollegeMajorLists")
    public  AjaxResult getCollegeMajorLists(@RequestBody CollegeMajorVos collegeMajorVos)
    {
        List<CollegeMajorVos> list = collegeMajorService.selectCollegeMajorLists(collegeMajorVos);
        return success(list);
    }


    /**
     * 查询列表不分页
     */
    @PostMapping("/getCollegeMajorLists1")
    public  AjaxResult getCollegeMajorLists1(@RequestBody CollegeMajorVos collegeMajorVos)
    {
        List<CollegeMajorVos> list = collegeMajorService.selectCollegeMajorLists1(collegeMajorVos);
        return success(list);
    }
    /**
     * 查询列表不分页
     */
    @GetMapping("/getCollegeMajorList")
    public  AjaxResult getCollegeMajorList(CollegeMajorVo collegeMajorVo)
    {
        List<CollegeMajorVo> list = collegeMajorService.selectCollegeMajorList(collegeMajorVo);
        return success(list);
    }

    /**
     * 导出学院专业列表
     */
    @Log(title = "学院专业", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CollegeMajorVo collegeMajorVo)
    {
        List<CollegeMajorVo> list = collegeMajorService.selectCollegeMajorList(collegeMajorVo);
        ExcelUtil<CollegeMajorVo> util = new ExcelUtil<CollegeMajorVo>(CollegeMajorVo.class);
        util.exportExcel(response, list, "学院专业数据");
    }

    /**
     * 获取学院专业详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(collegeMajorService.selectCollegeMajorById(id));
    }


    /**
     * 获取学院专业详细信息
     */
    @GetMapping(value = "/feign/{id}")
    public AjaxResult getFeignInfo(@PathVariable("id") Long id)
    {
        return success(collegeMajorService.selectCollegeMajorByIds(id));
    }

    /**
     * 新增学院专业
     */
    @Log(title = "学院专业", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CollegeMajorVo collegeMajorVo)
    {

        return collegeMajorService.insertCollegeMajor(collegeMajorVo);
    }

    /**
     * 修改学院专业
     */
    @Log(title = "学院专业", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CollegeMajorVo collegeMajorVo)
    {
        return toAjax(collegeMajorService.updateCollegeMajor(collegeMajorVo));
    }

    /**
     * 删除学院专业
     */
    @Log(title = "学院专业", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable("ids") List<Long> ids)
    {
        CollegeMajorVo collegeMajorVo=new CollegeMajorVo();
        collegeMajorVo=collegeMajorService.selectCollegeMajorById(ids.get(0));
        collegeMajorVo.setDeleteFlag("1");
        return toAjax(collegeMajorService.updateCollegeMajor(collegeMajorVo));
    }


}
